package com.jihu.design.behavioral.memento;

import lombok.Data;
import org.apache.commons.beanutils.BeanUtils;

import java.lang.reflect.InvocationTargetException;
import java.util.Random;

/**
 * 1.备忘录的设计（提取属性）
 * 2.备忘录对象和原对象互转操作
 * @author jihu
 * @date 2021/10/8
 */
@Data
public class LeiGamer {

    Integer coin;
    Integer hp;
    Integer mp;
    Integer level;

    GameServer gameServer = new GameServer();

    void saveGameRecord() throws Exception {
        System.out.println("正在保存当前记录......");
        GameRecord record = new GameRecord();
        BeanUtils.copyProperties(record,this);

        gameServer.add(record);
    }

    LeiGamer getFromMemento(Integer id) throws Exception {
        System.out.println("获取历史存档信息");

        LeiGamer record = gameServer.getRecord(id);
        return record;
    }

    void playGame(){
        System.out.println(".........<><>......");
        coin = new Random().nextInt();
        hp = new Random().nextInt();
        mp = new Random().nextInt();
        level = new Random().nextInt();
    }

    void exitGame(){
        System.out.println("退出&存档");
    }
}
